package com.chushouya.controller.manager.admin;

import com.chushouya.common.constant.ServiceType;
import com.chushouya.manager.dto.admin.banner.*;
import com.general.framework.core.enums.BusinessType;
import com.general.framework.core.schema.PageResult;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.Log;
import com.chushouya.manager.service.admin.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping(ServiceType.PLATFORM + "/banner")
@Api(tags = "banner管理")
public class BannerController {

    @Resource
    private BannerService bannerService;

    @GetMapping("/page")
    @ApiOperation("banner分页列表")
    public Response<PageResult<BannerListDTO>> page(BannerQuery query) {
        return Response.success(bannerService.selectPage(query));
    }

    @GetMapping("/detail")
    @ApiOperation("导航栏详情")
    public Response<BannerDetailDTO> detail(Long bannerId) {
        return Response.success(bannerService.detail(bannerId));
    }

    @PostMapping("/add")
    @ApiOperation("添加导航栏")
    @Log(businessType = BusinessType.INSERT)
    public Response<Void> save(@RequestBody @Valid BannerSaveDTO dto) {
        bannerService.save(dto);
        return Response.success();
    }

    @PostMapping("/edit")
    @ApiOperation("更新导航栏")
    @Log(businessType = BusinessType.UPDATE)
    public Response<Void> update(@RequestBody @Valid BannerUpdateDTO dto) {
        bannerService.update(dto);
        return Response.success();
    }

    @PostMapping("/remove")
    @ApiOperation("删除导航栏")
    @Log(businessType = BusinessType.DELETE)
    public Response<Void> remove(Long bannerId) {
        bannerService.delete(bannerId);
        return Response.success();
    }

}
